//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

static CTouchTimer g_touchTimer;
//static TOUCH_DATA  g_touchData;

void __stdcall onTimerExpiration(
               UINT wTimerID,
               UINT msg,
               DWORD dwUser,
               DWORD dw1,
               DWORD dw2)
{
    g_touchTimer.Stop();
    // TODO touch data;
}

class CTouchTimer
{
public:
    ECode Start(Millisecond msTimeout);
    //ECode Restart(Millisecond msTimeout);
    void  Stop();

private:
    UInt32 m_timerId;
};

ECode CTouchTimer::Start(Millisecond msTimeout)
{
    assert(0 == m_timerId);
    m_timerId = _StartTimer((UINT)seconds, onTimerExpiration, 0);
    if (!m_timerId) {
        // failed. todo;
    }
    return NOERROR;
}

/*
ECode CTouchTimer::Restart(Millisecond seconds)
{
    if (!m_timerId) {
        _StopTimer((UINT)m_timerId);
        m_timerId = 0;
    }
    m_timerId = _StartTimer((UINT)seconds, onTimerExpiration, 0);
    if (!m_timerId) {
        // failed. todo;
    }
    return NOERROR;
}
*/

void CTouchTimer::Stop()
{
    assert(0 != m_timerId);
    _StopTimer((UINT)m_timerId);
    m_timerId = 0;
}

void CTouchTimer::TouchNotify(Int32 type)
{
    if (type == TOUCH_DOWN) {
        Start(1) // 1 seconds;
    }
    else {
        Stop();
    }
}
